// pages/consumeResult/consumeResult.js
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    obj: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.globalData.post({
        url: '/client/payDetail',
        data: {
            clientId: options.clientId,
            consumptionId: options.consumptionId,
            shopId: app.globalData.shopId
        },
        success: (data) => {
            var sortRule = [1, 2, 4, 3];
            let detail = data.data.detail;
            var arr = [2, 3, 4, 1, 3, 4];
            var result = []
            for (let i = 0; i < detail.length; i++) {
                result = result.concat(detail.filter(m => m.couponPoolType == sortRule[i]))
            }
            data.data.detail = result
            data.data.detail.forEach(val => {
                let favorableRules = JSON.parse(val.favorableRules)
                if (val.couponPoolType == 1 || val.couponPoolType == 2){
                    favorableRules.value = (favorableRules.value/100).toFixed(2)
                    favorableRules.condition = (favorableRules.condition/100).toFixed(2)
                }
                else if (val.couponPoolType == 4){
                    favorableRules.value = favorableRules.value / 10 + '折'
                }
                else if (val.couponPoolType == 3){
                    // favorableRules.value = 'free'
                }
                val.favorableRules = favorableRules
            })
            data.data.summary.payAmount = (data.data.summary.payAmount/100).toFixed(2)
            data.data.summary.consumptionAmount = (data.data.summary.consumptionAmount/100).toFixed(2)
            
            this.setData({
                obj: data.data
            })
        }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})